package com.chai.service.impl;

import com.chai.dao.UserDao;
import com.chai.service.LogService;
import com.chai.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private LogService logService;
    /**
     * 转账
     */
    public void transfer(int outId,int inId,double money) {
        try {
            userDao.withdrawal(outId, money);
            //测试事务的设置时候成功
            //int i=1/0;
            userDao.deposit(inId, money);
            System.out.println("执行成功！");
        } finally {
            //无论是否异常都应该进行打印日志文件
            logService.log(inId,outId,money);
        }
    }
}
